package com.gz;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;

public class test_inputoroutiostream {
    public static void main(String[] args) {//static只能调用static方法
    outputiostream();
//        inputiostream_();
    }

    public static void inputiostream_(){
        //输入流
        String filepath="E:\\Java\\java_code\\test\\lianxi.txt";
        FileInputStream fileInputStream=null;
        byte [] buffer=new byte[8];
        int readlength=0;
        try {
            fileInputStream=new FileInputStream(filepath);
            while((readlength=fileInputStream.read(buffer))!=-1){
                System.out.print(new String(buffer,0,readlength));//如果是拷贝，可以从另一个文件用该方法配合write写入另一个文件
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileInputStream.close();//不要忘记！
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void outputiostream(){
        //输出流
        String filepath="E:\\Java\\java_code\\test\\lianxi.txt";
        FileOutputStream fileOutputStream=null;

        try {
                fileOutputStream=new FileOutputStream(filepath);//加true就是附加append的意思，不加就是覆盖
                String s="hello,world";
                fileOutputStream.write(s.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();//一定要写，否则最后不会录入！
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

class A{
    public void a(){}

    public void b(){
        a();
    }
}
